package com.ccx.coachsite;

import com.ccx.coachsite.ui.customview.IPageBar;
import com.ccx.coachsite.ui.customview.ViewPager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

public class GuideActivity extends Activity {

	private ViewPager viewPager;
	private ImageView lastNavImage;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main_guide);

		viewPager = (ViewPager) findViewById(R.id.main_guide_content);
		GuidePageBar guidePageBar = new GuidePageBar();
		viewPager.setTab(guidePageBar);
		viewPager.setToScreen(0);

		lastNavImage = (ImageView) findViewById(R.id.guide_last_page);
		lastNavImage.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				navigateToSplash();
			}
		});
	}

	private void navigateToSplash() {
		Intent intent = new Intent(this, MainSplash.class);
		startActivity(intent);
		finish();
	}

	class GuidePageBar implements IPageBar {

		private int page = -1;

		@Override
		public void scrollHighLight(int scrollX) {
			if (page >= viewPager.getChildCount() - 1) {
				Log.d("GuidePageBar", String.valueOf(scrollX));
				int pageWidth = viewPager.getWidth();
				if (scrollX > pageWidth * page + pageWidth / 3)
					navigateToSplash();
			}
		}

		@Override
		public void updateSelected(int page) {
			this.page = page;
		}
	}
}
